<template>
    <div>
        <van-nav-bar
                :fixed="fixed"
                title="我的邀请"
                left-text="返回"
                left-arrow
                @click-left="onClickLeft"
        />
        <van-list
                v-model="loading"
                :finished="finished"
                @load="onLoad"
                :offset="10"
                style="padding-top: 46px"
                v-if="list!=''"
        >
            <ul v-for="(item,index) in list" :key="index" >
                <van-cell-group>
                    <van-cell :title=item.user.user_nickname :value=formatTime(item.create_time)  />
                </van-cell-group>
            </ul>
        </van-list>
        <div class="user-buttom loading-no-more" v-show="show">
            <span>我也是有底线的~~~~~~~~~~</span>
        </div>
        <div v-if="list==''" class="user-null">
            <span>您还没有邀请的用户！！！</span>
        </div>
    </div>
</template>

<script>
    import Vue from 'vue'
    import { List } from 'vant';
    Vue.use(List);
    import {InvitationUser} from "../api/data";
    export default {
        data(){
            return{
                fixed:true,
                list:[],
                loading: false,
                finished: false,
                page:1,
                user_id:'',
                show:false
            }
        },
        methods:{
            onClickLeft:function () {
                this.$router.back()
            },
            formatTime(time) {
                let createDate = new Date();
                createDate.setTime(time * 1000);
                return createDate.format('yyyy-MM-dd hh:mm');
            },
            onLoad() {
                // 异步更新数据
                setTimeout(() => {
                    this.page++;
                    InvitationUser(this.user_id,this.page).then(res=>{
                        for (var i=0;i<res.data.data.data.length;i++){
                            this.list.push(res.data.data.data[i])
                        }
                        // 加载状态结束
                        this.loading = false;
                        // 数据全部加载完成
                        if (res.data.data.data.length==0) {
                            this.show = true;
                            this.usershow =true;
                            this.finished = true;
                        }
                    })
                }, 2000);
            }
        },
        mounted(){
            let user_id =JSON.parse(localStorage.getItem('user'))
            this.user_id = user_id.id
            InvitationUser(this.user_id,this.page).then(res=>{
                console.log(res.data.data.data)
                this.list=res.data.data.data
            })
        }
    }
</script>

<style scoped>
    .user-null{
        padding-top: 100px;
        width: 100%;
        height: 100px;
        line-height: 100px;
        text-align: center;
    }
</style>